(function () {
  // ...
  // console.log(info());
  let userIpt = document.querySelector('.user-name')
  let emailIpt = document.querySelector('.user-email')
  let hintEmail = document.querySelector('.hintemail')
  let hintUser = document.querySelector('.hintuser')
  let loginId = document.querySelector('.login-id')
  let putBtn = document.querySelector('.btn')
  let resetBtn = document.querySelector('.resetbtn')

  async function get() {
    let res = await info()
    loginId.value = res.data.data.username
  }
  get()

  //用户邮箱失焦
  userIpt.addEventListener('blur', function () {
    if (userIpt.value !== '') {
      hintUser.style.display = 'none'
    } else {
      hintUser.style.display = 'block'
    }
  })
  emailIpt.addEventListener('blur', function () {
    if (emailIpt.value !== '') {
      hintEmail.style.display = 'none'
    } else {
      hintEmail.style.display = 'block'
    }
  })

  //用户邮箱重置
  resetBtn.addEventListener('click', function (e) {
    userIpt.value = ''
    emailIpt.value = ''
    e.preventDefault();
    hintUser.style.display = 'none'
    hintEmail.style.display = 'none'
  })

  // 获取用户基本信息
  putBtn.addEventListener('click', async function (e) {
    e.preventDefault();
    if (userIpt.value !== '' || emailIpt.value !== '') {
      hintUser.style.display = 'none'
      hintEmail.style.display = 'none'
      let res2 = await info();
      let id = res2.data.data.id;
      let obj = {
        "id": parseInt(id),
        "nickname": userIpt.value,
        "email": emailIpt.value
      }
      let res1 = await infos(obj);
      window.parent.location.reload() 
    } else {
      hintUser.style.display = 'block'
      hintEmail.style.display = 'block'
    }

  })


})()